// function getLanguageFromURL() {
//   const regex = new RegExp('[\\?&]lang=([^&#]*)');
//   const results = regex.exec(window.location.search);
//   return results === null ? null : decodeURIComponent(results[1].replace(/\+/g, ' '));
// }

const DataFeeds = require("../tvlib/datafeeds/udf/src/udf-compatible-datafeed");

const ins = {
  cfg: null,
  init(cfg) {
    this.cfg = cfg;

    if (this.cfg.isLight) {
      this.widgetOpts = this.widgetOptsLight;
    } else {
      this.widgetOpts = this.widgetOptsDefault;
    }

    this.widgetOpts.container_id = cfg.id;
    this.widgetOpts.datafeed = new DataFeeds.UDFCompatibleDatafeed(
      cfg.url,
      1000,
      {
        symbol: cfg.symbol,
        skService: cfg.skService
      }
    );
    this.widgetOpts.symbol = cfg.symbol;
    this.widgetOpts.interval = "1";
    this.widgetOpts.library_path = "/assets/tvlib/charting_library/";
    this.widgetOpts.locale = cfg.locale || "en";
  },
  widgetOptsLight: {
    container_id: "",
    loading_screen: {
      // foregroundColor: "#000000",
      // backgroundColor: "#000000",
    },
    debug: false,
    // locale: getLanguageFromURL() || 'en',
    locale: "en",
    favorites: {
      intervals: ["1", "5", "10", "15", "30", "60", "240", "D", "7D", "W", "M"]
    },
    logo: {},
    timezone: undefined,
    library_path: "/tvlib/charting_library/",
    disabled_features: [
      "header_saveload",
      "compare_symbol",
      "display_market_status",
      "go_to_date",
      "header_compare",
      "header_interval_dialog_button",
      "header_screenshot",
      "header_symbol_search",
      "header_undo_redo",
      "legend_context_menu",
      "show_hide_button_in_legend",
      "show_interval_dialog_on_key_press",
      "snapshot_trading_drawings",
      "symbol_info",
      "timeframes_toolbar",
      "use_localstorage_for_settings",
      "volume_force_overlay"
    ],
    enabled_features: [
      "dont_show_boolean_study_arguments",
      "hide_last_na_study_output",
      // 'move_logo_to_main_pane',
      "same_data_requery",
      "side_toolbar_in_fullscreen_mode",
      "hide_left_toolbar_by_default"
    ],
    charts_storage_url: "https://saveload.tradingview.com",
    charts_storage_api_version: "1.1",
    client_id: "tradingview.com",
    user_id: "public_user_id",
    fullscreen: false,
    autosize: true,
    studies_overrides: {},
    // toolbar_bg: "#181b2a",
    overrides: {
      // "paneProperties.background":"#181b2a",
      // "paneProperties.horzGridProperties.color":"#202a43",
      // "paneProperties.vertGridProperties.color":"#202a43",
      // "scalesProperties.lineColor":"#60678a",
      // "scalesProperties.textColor":"#60678a",
      // "scalesProperties.textColor":"#60678a",
      "paneProperties.legendProperties.showLegend": false,

      volumePaneSize: "medium",
      // "paneProperties.crossHairProperties.color": "#9194A3",
      "paneProperties.legendProperties.showStudyArguments": !0,
      "paneProperties.legendProperties.showStudyTitles": !0,
      "paneProperties.legendProperties.showStudyValues": !0,
      "paneProperties.legendProperties.showSeriesTitle": !0,
      "paneProperties.legendProperties.showSeriesOHLC": !0,

      "mainSeriesProperties.candleStyle.upColor": "#29a76c", //绿
      "mainSeriesProperties.candleStyle.downColor": "#df543a", //红
      "mainSeriesProperties.candleStyle.drawWick": !0,
      "mainSeriesProperties.candleStyle.drawBorder": !0,
      "mainSeriesProperties.candleStyle.borderColor": "#4e5b85",
      "mainSeriesProperties.candleStyle.borderUpColor": "#29a76c", //绿
      "mainSeriesProperties.candleStyle.borderDownColor": "#df543a", //红
      "mainSeriesProperties.candleStyle.wickUpColor": "#29a76c", //绿
      "mainSeriesProperties.candleStyle.wickDownColor": "#df543a", //红
      "mainSeriesProperties.candleStyle.barColorsOnPrevClose": !1,

      "mainSeriesProperties.hollowCandleStyle.upColor": "#29a76c", //绿
      "mainSeriesProperties.hollowCandleStyle.downColor": "#df543a", //红
      "mainSeriesProperties.hollowCandleStyle.drawWick": !0,
      "mainSeriesProperties.hollowCandleStyle.drawBorder": !0,
      "mainSeriesProperties.hollowCandleStyle.borderColor": "#4e5b85",
      "mainSeriesProperties.hollowCandleStyle.borderUpColor": "#29a76c", //绿
      "mainSeriesProperties.hollowCandleStyle.borderDownColor": "#df543a", //红
      "mainSeriesProperties.hollowCandleStyle.wickColor": "#373843",

      "mainSeriesProperties.haStyle.upColor": "#29a76c", //绿
      "mainSeriesProperties.haStyle.downColor": "#df543a", //红
      "mainSeriesProperties.haStyle.drawWick": !0,
      "mainSeriesProperties.haStyle.drawBorder": !0,
      "mainSeriesProperties.haStyle.borderColor": "#4e5b85",
      "mainSeriesProperties.haStyle.borderUpColor": "#29a76c", //绿
      "mainSeriesProperties.haStyle.borderDownColor": "#df543a", //红
      "mainSeriesProperties.haStyle.wickColor": "#4e5b85",
      "mainSeriesProperties.haStyle.barColorsOnPrevClose": !1,

      "mainSeriesProperties.barStyle.upColor": "#29a76c", //绿
      "mainSeriesProperties.barStyle.downColor": "#df543a", //红
      "mainSeriesProperties.barStyle.barColorsOnPrevClose": !1,
      "mainSeriesProperties.barStyle.dontDrawOpen": !1,

      "mainSeriesProperties.lineStyle.color": "#4e5b85",
      "mainSeriesProperties.lineStyle.linewidth": 1,
      "mainSeriesProperties.lineStyle.priceSource": "close",
      "mainSeriesProperties.areaStyle.color1": "rgba(122, 152, 247, .1)",
      "mainSeriesProperties.areaStyle.color2": "rgba(122, 152, 247, .02)",
      "mainSeriesProperties.areaStyle.linecolor": "#4e5b85",
      "mainSeriesProperties.areaStyle.linewidth": 1,
      "mainSeriesProperties.areaStyle.priceSource": "close"
    }
  },
  widgetOptsDefault: {
    container_id: "",
    loading_screen: {
      foregroundColor: "#000000",
      backgroundColor: "#000000"
    },
    debug: false,
    // locale: getLanguageFromURL() || 'en',
    locale: "en",
    favorites: {
      intervals: ["1", "5", "10", "15", "30", "60", "240", "D", "7D", "W", "M"]
    },
    logo: {},
    timezone: undefined,
    library_path: "/tvlib/charting_library/",
    disabled_features: [
      "header_saveload",
      "compare_symbol",
      "display_market_status",
      "go_to_date",
      "header_compare",
      "header_interval_dialog_button",
      "header_screenshot",
      "header_symbol_search",
      "header_undo_redo",
      "legend_context_menu",
      "show_hide_button_in_legend",
      "show_interval_dialog_on_key_press",
      "snapshot_trading_drawings",
      "symbol_info",
      "timeframes_toolbar",
      "use_localstorage_for_settings",
      "volume_force_overlay"
    ],
    enabled_features: [
      "dont_show_boolean_study_arguments",
      "hide_last_na_study_output",
      // 'move_logo_to_main_pane',
      "same_data_requery",
      "side_toolbar_in_fullscreen_mode",
      "hide_left_toolbar_by_default"
    ],
    charts_storage_url: "https://saveload.tradingview.com",
    charts_storage_api_version: "1.1",
    client_id: "tradingview.com",
    user_id: "public_user_id",
    fullscreen: false,
    autosize: true,
    studies_overrides: {},
    toolbar_bg: "#181b2a",
    overrides: {
      "paneProperties.background": "#181b2a",
      "paneProperties.horzGridProperties.color": "#202a43",
      "paneProperties.vertGridProperties.color": "#202a43",
      "scalesProperties.lineColor": "#60678a",
      "scalesProperties.textColor": "#60678a",
      "scalesProperties.textColor": "#60678a",
      "paneProperties.legendProperties.showLegend": false,

      volumePaneSize: "medium",
      "paneProperties.crossHairProperties.color": "#9194A3",
      "paneProperties.legendProperties.showStudyArguments": !0,
      "paneProperties.legendProperties.showStudyTitles": !0,
      "paneProperties.legendProperties.showStudyValues": !0,
      "paneProperties.legendProperties.showSeriesTitle": !0,
      "paneProperties.legendProperties.showSeriesOHLC": !0,
      "mainSeriesProperties.candleStyle.upColor": "#589065",
      "mainSeriesProperties.candleStyle.downColor": "#ae4e54",
      "mainSeriesProperties.candleStyle.drawWick": !0,
      "mainSeriesProperties.candleStyle.drawBorder": !0,
      "mainSeriesProperties.candleStyle.borderColor": "#4e5b85",
      "mainSeriesProperties.candleStyle.borderUpColor": "#589065",
      "mainSeriesProperties.candleStyle.borderDownColor": "#ae4e54",
      "mainSeriesProperties.candleStyle.wickUpColor": "#589065",
      "mainSeriesProperties.candleStyle.wickDownColor": "#ae4e54",
      "mainSeriesProperties.candleStyle.barColorsOnPrevClose": !1,
      "mainSeriesProperties.hollowCandleStyle.upColor": "#589065",
      "mainSeriesProperties.hollowCandleStyle.downColor": "#ae4e54",
      "mainSeriesProperties.hollowCandleStyle.drawWick": !0,
      "mainSeriesProperties.hollowCandleStyle.drawBorder": !0,
      "mainSeriesProperties.hollowCandleStyle.borderColor": "#4e5b85",
      "mainSeriesProperties.hollowCandleStyle.borderUpColor": "#589065",
      "mainSeriesProperties.hollowCandleStyle.borderDownColor": "#ae4e54",
      "mainSeriesProperties.hollowCandleStyle.wickColor": "#373843",
      "mainSeriesProperties.haStyle.upColor": "#589065",
      "mainSeriesProperties.haStyle.downColor": "#ae4e54",
      "mainSeriesProperties.haStyle.drawWick": !0,
      "mainSeriesProperties.haStyle.drawBorder": !0,
      "mainSeriesProperties.haStyle.borderColor": "#4e5b85",
      "mainSeriesProperties.haStyle.borderUpColor": "#589065",
      "mainSeriesProperties.haStyle.borderDownColor": "#ae4e54",
      "mainSeriesProperties.haStyle.wickColor": "#4e5b85",
      "mainSeriesProperties.haStyle.barColorsOnPrevClose": !1,
      "mainSeriesProperties.barStyle.upColor": "#589065",
      "mainSeriesProperties.barStyle.downColor": "#ae4e54",
      "mainSeriesProperties.barStyle.barColorsOnPrevClose": !1,
      "mainSeriesProperties.barStyle.dontDrawOpen": !1,
      "mainSeriesProperties.lineStyle.color": "#4e5b85",
      "mainSeriesProperties.lineStyle.linewidth": 1,
      "mainSeriesProperties.lineStyle.priceSource": "close",
      "mainSeriesProperties.areaStyle.color1": "rgba(122, 152, 247, .1)",
      "mainSeriesProperties.areaStyle.color2": "rgba(122, 152, 247, .02)",
      "mainSeriesProperties.areaStyle.linecolor": "#4e5b85",
      "mainSeriesProperties.areaStyle.linewidth": 1,
      "mainSeriesProperties.areaStyle.priceSource": "close"
    }
  },
  widgetOpts: {}
};

export default ins;
